package com.czk.classreader.method.addcode;

import java.lang.reflect.Method;

/**
 * 方法进入和退出时添加代码的测试
 *
 * @Author:ChenZhangKun
 * @Date: 2021/8/16 17:08
 */
public class Test {
    public static void main(String[] args) throws Exception {
        // 反射
        Class<?> clazz = Class.forName("com.czk.sample.Test");
        // 拿到方法
        Object o = clazz.newInstance();
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName());
            // Method Enter...
            // 你好
            declaredMethod.invoke(o, true);
        }
    }
}
